Appium Essentials by Hans Manoj

Appium Essentials by Hans Manoj

Author:Hans, Manoj
Language: eng
Format: epub
Publisher: Packt Publishing
Published: 2015-04-08T16:00:00+00:00


We are done with the desired capabilities part; now, we have to initiate the Android Driver to connect with the Appium server, but first we need to import the following packages:

import io.appium.java_client.android.AndroidDriver; import java.net.URL;

Then, initiate the Android Driver:

AndroidDriver driver = new AndroidDriver (new URL("http://127.0.0.1:4723/wd/hub"), caps);

This will launch the app in the Android emulator using the configurations specified in the desired capabilities.

Now, you can use the following class to write the test scripts with TestNG:

import io.appium.java_client.android.AndroidDriver; import io.appium.java_client.remote.MobileCapabilityType; import java.io.File; import java.net.MalformedURLException; import java.net.URL; import java.util.concurrent.TimeUnit; import org.openqa.selenium.remote.DesiredCapabilities; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; public class TestAppIication { AndroidDriver driver; @BeforeClass public void setUp() throws MalformedURLException{ //Set up desired capabilities DesiredCapabilities caps = new DesiredCapabilities(); File app=new File("path of the apk"); caps.setCapability(MobileCapabilityType.APP,app); caps.setCapability(MobileCapabilityType.PLATFORM_VERSION, "4.4"); caps.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android"); caps.setCapability(MobileCapabilityType.DEVICE_NAME, "Android emulator"); caps.setCapability("avd","Name of the AVD to launch"); caps.setCapability(MobileCapabilityType.APP_PACKAGE, "package name of your app (you can get it from apk info app)"); caps.setCapability(MobileCapabilityType.APP_ACTIVITY, "Launch activity of your app (you can get it from apk info app)"); caps.setCapability(MobileCapabilityType.BROWSER_NAME, "Browser");// In case of web apps driver = new AndroidDriver (new URL("http://127.0.0.1:4723/wd/hub"), caps); driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS); } @Test public void testExample(){ //We will put test scripts here } @AfterClass public void tearDown(){ driver.closeApp();//CloseApp() function is used to close the mobile native and hybrid apps while quit() and close() is used for web apps } }



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.